package com.zx.kitchen.index.common.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zx.kitchen.index.R;
import com.zx.kitchen.index.common.entity.GoodDetailBean;
import com.zx.kitchen.index.common.entity.GoodDetailListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/21.
 */

public class GoodsReportDetailAdapter extends BaseAdapter {


    private List<GoodDetailListBean> objects = new ArrayList<GoodDetailListBean>();

    private Context context;
    private LayoutInflater layoutInflater;

    public GoodsReportDetailAdapter(Context context, List<GoodDetailListBean> objects) {
        this.context = context;
        this.objects = objects;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public GoodDetailListBean getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.adapter_goods_report_detail, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((GoodDetailListBean) getItem(position), (ViewHolder) convertView.getTag(),position);
        return convertView;
    }

    private void initializeViews(GoodDetailListBean object, ViewHolder holder,int position) {
        holder.reportDate.setText("时间：   "+object.getDetail().get(position).getD());
        holder.reportUnit.setText("单位：   "+object.getDishes().getUnit());
        holder.reportPrice.setText("单价：   "+object.getDetail().get(position).getPrice()+"元");
        holder.reportNum.setText("数量：   "+object.getDetail().get(position).getNum());
        holder.reportTotal.setText("营业总额：   "+object.getDetail().get(position).getTotal()+"元");

    }

    protected class ViewHolder {

        private TextView reportDate;
        private TextView reportUnit;
        private TextView reportPrice;
        private TextView reportNum;
        private TextView reportTotal;

        public ViewHolder(View view) {

            reportDate = (TextView) view.findViewById(R.id.report_date);
            reportUnit = (TextView) view.findViewById(R.id.report_unit);
            reportPrice = (TextView) view.findViewById(R.id.report_price);
            reportNum = (TextView) view.findViewById(R.id.report_num);
            reportTotal = (TextView) view.findViewById(R.id.report_total);
        }
    }
}
